import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDEquipmentRMath {
	/**装备id*/
	id,
	/**物理攻击，数组[下限,上限]*/
	phyAtk,
	/**火焰攻击，数组[下限,上限]*/
	fireAtk,
	/**冰冻攻击，数组[下限,上限]*/
	iceAtk,
	/**闪电攻击，数组[下限,上限]*/
	lightAtk,
	/**生命，数组[下限,上限]*/
	hp,
	/**生命恢复，数组[下限,上限]*/
	hpRegen,
	/**魔法恢复，数组[下限,上限]*/
	manaRegen,
	/**连击恢复，数组[下限,上限]*/
	dribbleRegen,
	/**闪避恢复，数组[下限,上限]*/
	dodgeRegen,
	/**暴击恢复，数组[下限,上限]*/
	critRegen,
	/**格挡恢复，数组[下限,上限]*/
	blockRegen,

	/**枚举数量*/
	EnumCount
}



export class CDEquipmentRMath{
	/**装备id*/
	public id: number;
	/**物理攻击，数组[下限,上限]*/
	public phyAtk: number[];
	/**火焰攻击，数组[下限,上限]*/
	public fireAtk: number[];
	/**冰冻攻击，数组[下限,上限]*/
	public iceAtk: number[];
	/**闪电攻击，数组[下限,上限]*/
	public lightAtk: number[];
	/**生命，数组[下限,上限]*/
	public hp: number[];
	/**生命恢复，数组[下限,上限]*/
	public hpRegen: number[];
	/**魔法恢复，数组[下限,上限]*/
	public manaRegen: number[];
	/**连击恢复，数组[下限,上限]*/
	public dribbleRegen: number[];
	/**闪避恢复，数组[下限,上限]*/
	public dodgeRegen: number[];
	/**暴击恢复，数组[下限,上限]*/
	public critRegen: number[];
	/**格挡恢复，数组[下限,上限]*/
	public blockRegen: number[];


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDEquipmentRMath.id: return this.id;
			case E_CDEquipmentRMath.phyAtk: return this.phyAtk;
			case E_CDEquipmentRMath.fireAtk: return this.fireAtk;
			case E_CDEquipmentRMath.iceAtk: return this.iceAtk;
			case E_CDEquipmentRMath.lightAtk: return this.lightAtk;
			case E_CDEquipmentRMath.hp: return this.hp;
			case E_CDEquipmentRMath.hpRegen: return this.hpRegen;
			case E_CDEquipmentRMath.manaRegen: return this.manaRegen;
			case E_CDEquipmentRMath.dribbleRegen: return this.dribbleRegen;
			case E_CDEquipmentRMath.dodgeRegen: return this.dodgeRegen;
			case E_CDEquipmentRMath.critRegen: return this.critRegen;
			case E_CDEquipmentRMath.blockRegen: return this.blockRegen;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDEquipmentRMath.id: this.id = v; break;
			case E_CDEquipmentRMath.phyAtk: this.phyAtk = v; break;
			case E_CDEquipmentRMath.fireAtk: this.fireAtk = v; break;
			case E_CDEquipmentRMath.iceAtk: this.iceAtk = v; break;
			case E_CDEquipmentRMath.lightAtk: this.lightAtk = v; break;
			case E_CDEquipmentRMath.hp: this.hp = v; break;
			case E_CDEquipmentRMath.hpRegen: this.hpRegen = v; break;
			case E_CDEquipmentRMath.manaRegen: this.manaRegen = v; break;
			case E_CDEquipmentRMath.dribbleRegen: this.dribbleRegen = v; break;
			case E_CDEquipmentRMath.dodgeRegen: this.dodgeRegen = v; break;
			case E_CDEquipmentRMath.critRegen: this.critRegen = v; break;
			case E_CDEquipmentRMath.blockRegen: this.blockRegen = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDEquipmentRMath> = new HashMap<number, CDEquipmentRMath>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDEquipmentRMath[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDEquipmentRMath();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].phyAtk = [];
			const attrArray = list[i].phyAtk;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].fireAtk = [];
			const attrArray = list[i].fireAtk;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].iceAtk = [];
			const attrArray = list[i].iceAtk;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].lightAtk = [];
			const attrArray = list[i].lightAtk;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].hp = [];
			const attrArray = list[i].hp;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].hpRegen = [];
			const attrArray = list[i].hpRegen;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].manaRegen = [];
			const attrArray = list[i].manaRegen;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].dribbleRegen = [];
			const attrArray = list[i].dribbleRegen;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].dodgeRegen = [];
			const attrArray = list[i].dodgeRegen;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].critRegen = [];
			const attrArray = list[i].critRegen;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].blockRegen = [];
			const attrArray = list[i].blockRegen;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDEquipmentRMath{
		return this.datas ? this.datas.get(id) : null;
	}
}
